<?php
  // session already started
  //session_start();
require('dbconnection.php');
require("pageform.php");
$header = "";
$header = addHeader("Captcha Collection");
echo($header);
db_connect();

$username= $_SESSION['uname'];


$initialGameNum = 0;


?>

<div id="menucontainer">
  <div id="menu">
  <div id="navcontainer">
  <ul id="navlist">
  <li><a title="Logout" href="endofprocess.php">Logout</a></li>
</ul>
</div>
</div>
</div>


<div id="content">

  <h2>What would other people say about this image?</h2>
<div id="display">
  <table>
<tr>
<?php
	  
$query = "SELECT number, path  FROM pics ORDER BY RAND() LIMIT 1";
$result = mysql_query($query);

	
if (!$result)
  throw new Exception("There is no result");
	
$query_row = mysql_fetch_row($result);
	
// $img is used later in the code
$img = $query_row[0];

echo  "<td>\n";
echo	"<img src=\"". $query_row[1] ."\" id=\"catimg\"/> \n";
echo  "</td>\n";

?>
<td>
<table id="taboowords" id="tbwords" >
  <tr>
<td><h2>TABOO WORDS</h2></td>
</tr>



<?php
 // Number of Taboo words

$query = "SELECT word, count(word) as frequency from descriptors where pic_number='$img' group by word order by frequency  limit 6";
$result = mysql_query($query);


if (!$result)
  throw new Exception("There is no results for ".$query);
		


// Number limited by the query
$numrows = 0;
while(	$query_row = mysql_fetch_row($result)){
  echo "<tr>\n";
  echo	"<td id='taboo".$numrows."'><h4>".$query_row[0]."</h4></td></tr>\n";
  $numrows++;
 }


// Magic Numbe is six because of num rows!!!	
if($numrows < 6){

  
  for ( $counter = $numrows; $counter < 6; $counter++) {

    echo "<tr>\n";
    echo	"<td id='taboo".$counter."'><h4>&nbsp;</h4></td></tr>\n";
    echo "</tr>\n";

  }

 }

?>
</table>
</td>
</tr>
</table>

</div>

<div id="form">
  <form name="f1"  id="f1"/>
  <h5>Term: <input type="text" onkeypress="return check(event)"  name="name" id="name" />
  <input type="button"onClick="labelImage()" value="Label" />
  <input type="button"onClick="passImage()" value="Pass" />
  <input type="hidden" id="currentattempt" name=" currentattempt" value="<?php echo $initialGameNum; ?>" />
  <input type="hidden" id="username" name="username" value="<?php echo $username; ?>" />
  </h5>
  </form>
  </div>	


  </div>
  <?php
  echo(addFooter());

?>
